# _*_ encoding:utf-8 _*_
"""
用户的模型
"""
# python 源生包
from datetime import datetime
# 第三方库
from django.db import models
from django.contrib.auth.models import AbstractUser # 引入Django自带的User模型
# 自定义的包
# Create your models here.


# 继承 Django 自带的User
class UserProfile(AbstractUser):
    # 自定义的字段
    nick_name = models.CharField(max_length=50, verbose_name="昵称")
    birthday = models.DateField(verbose_name="生日", null=True, blank=True) # 可为空
    gender = models.CharField(choices=(("male", "男"), ("female", "女")), default="female", max_length=10)
    address = models.CharField(max_length=100, default="") # 默认为空
    mobile = models.CharField(max_length=11, null=True, blank=True)
    image = models.ImageField(upload_to="image/%Y/%m", default="image/default.png", max_length=100)

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.username


# 邮箱验证码
class EmailVerifyRecord(models.Model):
    code = models.CharField(max_length=20, verbose_name="验证码")
    email = models.EmailField(max_length=50, verbose_name="邮箱")
    send_type = models.CharField(choices=(("register", "注册"), ("forget", "找回密码")), max_length=10, verbose_name="验证码类型")
    send_time = models.DateField(default=datetime.now, verbose_name="发送时间") # 这里不能加 ()， 如果加了的话，就会用编译的时间作为当前时间

    class Meta:
        verbose_name = "邮箱验证码"
        verbose_name_plural = verbose_name


# 轮播图
class Banner(models.Model):
    title = models.CharField(max_length=100, verbose_name="标题")
    image = models.ImageField(upload_to="banner/%Y/%m", verbose_name="轮播图", max_length=100)
    url = models.URLField(max_length=200, verbose_name="访问地址")
    index = models.IntegerField(default=100, verbose_name="顺序")
    add_time = models.DateField(default=datetime.now, verbose_name="添加时间") # 这里不能加 ()， 如果加了的话，就会用编译的时间作为当前时间

    class Meta:
        verbose_name = "轮播图"
        verbose_name_plural = verbose_name
